﻿<template>
  <div style="padding:0px;">
    <el-form :model="dialogForm" :rules="rules" ref="dialogForm" :label-width="formLabelWidth">

      <el-card class="box-card">
        <div class="text item">
          <div slot="header" class="clearfix">
            <span style="line-height: 30px;">实名信息</span>
          </div>
          <el-form-item label="使用者手机号码">
            <el-input v-model="dialogForm.phone" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="使用者真实姓名">
            <el-input v-model="dialogForm.person" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="身份证号码">
            <el-input v-model="dialogForm.idCard" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="认证状态">
            <el-input v-model="dialogForm.statusString" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="实名认证时间">
            <el-input :value="getDate(dialogForm.realNameAuthenticationTime)" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="实名认证审核人">
            <el-input v-model="dialogForm.realNameAuthenticationPerson" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="实名认证备注">
            <el-input v-model="dialogForm.realNameAuthenticationRemake" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="身份证照片">
            <qiniu :qiniuImage="dialogForm.idCardPics" :id="dialogForm.idCardPics.id" :canDelete="false"></qiniu>
          </el-form-item>
        </div>
      </el-card>
      <el-card class="box-card">
        <div class="text item">

          <div slot="header" class="clearfix">
            <span style="line-height: 30px;">公司信息</span>
          </div>
          <el-form-item label="经销商名称">
            <el-input v-model="dialogForm.name" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="注册详细地址">
            <el-input v-model="dialogForm.address" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="法人姓名" class="half">
            <el-input v-model="dialogForm.legalPersonName" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="法人手机号码" class="half">
            <el-input v-model="dialogForm.legalPersonPhone" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="法人身份证号码">
            <el-input v-model="dialogForm.legalPersonId" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="统一社会信用代码">
            <el-input v-model="dialogForm.documentId" auto-complete="off" disabled></el-input>
          </el-form-item>

          <el-form-item label="营业执照">
            <qiniu :qiniuImage="dialogForm.businessLicenses" :id="dialogForm.businessLicenses.id" :canDelete="false"></qiniu>
          </el-form-item>
          <el-form-item label="法人身份证照片">
            <qiniu :qiniuImage="dialogForm.legalPersonPics" :id="dialogForm.legalPersonPics.id" :canDelete="false"></qiniu>
          </el-form-item>

        </div>
      </el-card>
      <el-card class="box-card" style="margin-top:15px;">
        <div class="text item">
          <div slot="header" class="clearfix">
            <span style="line-height: 30px;">企业认证</span>
          </div>
          <el-form-item label="垫资利率" prop="interestRate" :rules="this.dialogForm.status!=2?rules.interestRate:[{ required: false}]">
            <el-input v-model.number="dialogForm.interestRate" auto-complete="off" :disabled="!authDialogFormVisible.isAdd" @blur="FormatInterestRate('interestRate')"></el-input>
          </el-form-item>
          <el-form-item label="库融利率" prop="mortgageInterestRate" :rules="this.dialogForm.status!=2?rules.mortgageInterestRate:[{ required: false}]">
            <el-input v-model.number="dialogForm.mortgageInterestRate" auto-complete="off" :disabled="!authDialogFormVisible.isAdd" @blur="FormatInterestRate('mortgageInterestRate')"></el-input>
          </el-form-item>
          <el-form-item label="经销商类别" prop="category" :rules="(this.dialogForm.status!=2||this.dialogForm.category=='')?rules.category:[{ required: false}]">
            <el-select v-model="dialogForm.category" placeholder="请选择经销商类别" :disabled="!authDialogFormVisible.isAdd">
              <el-option label="请选择经销商类别" value="">
              </el-option>
              <el-option v-for="(item, index) in type" :label="item" :value="index-0" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务员">
            <el-select v-model="dialogForm.businessSysUsersId" placeholder="请选择业务员" :disabled="!authDialogFormVisible.isAdd">
              <el-option label="请选择业务员" value="">
              </el-option>
              <el-option v-for="(item,index) in yewuyuan" :label="item.realname" :value="item.id" :key="index">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="地推员">
            <el-select v-model="dialogForm.pushSysUsersId" placeholder="请选择地推员" :disabled="!authDialogFormVisible.isAdd">
              <el-option label="请选择地推员" value="">
              </el-option>
              <el-option v-for="(item,index) in ditui" :label="item.realname" :value="item.id" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="资源员">
            <el-select v-model="dialogForm.resourceSysUsersId" placeholder="请选择资源员" :disabled="!authDialogFormVisible.isAdd">
              <el-option label="请选择资源员" value="">
              </el-option>
              <el-option v-for="(item,index) in ziyuan" :label="item.realname" :value="item.id" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="企业认证信息" prop="status">
            <el-radio-group v-model="dialogForm.status" :disabled="!authDialogFormVisible.isAdd">
              <el-radio :label="1">通过</el-radio>
              <el-radio :label="2">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="企业认证备注" prop="remark">
            <el-input type="textarea" :rows=3 v-model="dialogForm.remark" :disabled="!authDialogFormVisible.isAdd" auto-complete="off"></el-input>
          </el-form-item>
          <template v-if='!authDialogFormVisible.isAdd'>
            <el-row>
              <el-col :span="12">
                <el-form-item label="企业认证时间">
                  <el-input :rows=3 :value="getDate(dialogForm.authenticationTime)" disabled auto-complete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="企业认证审核人">
                  <el-input  :rows=3 v-model="dialogForm.authenticationPerson" disabled auto-complete="off"></el-input>
                </el-form-item> 
                
              </el-col>
            </el-row>


          </template>
        </div>
      </el-card>
      <div style="text-align:right;margin-top:15px;">
        <el-button @click="submitConfirmForm('dialogForm')" v-if="authDialogFormVisible.isAdd">提交</el-button>
        <el-button @click="returnBack('dialogForm')">返 回</el-button>
      </div>
    </el-form>
  </div>
</template>
<script>
  import qiniu from '@/views/qiniu/upload';
  import agentHttp from '@/utils/agentHttp.js';
  import {
    require,
    decimalFour,
    max100
  } from '@/utils/rules.js';
  import {
    timestampToTime
  } from '@/utils/index.js'
  export default {
    created() {
      if (this.authDialogFormVisible.id !== "") {
        //修改
        this.selectData();

      }
    },
    components: {
      qiniu
    },
    props: ['authDialogFormVisible'],
    data() {
      return {
        formLabelWidth: '170px',
        yewuyuan: {},
        ditui: {},
        ziyuan: {},
        type: {},
        //弹窗或者查看页面信息
        dialogForm: {
          category: ""
        },
        rules: {
          name: [require('经销商名称')],
          category: [require('经销商类别')],
          interestRate: [require('垫资利率', {
            // trigger: "blur"
          }), {
            validator: decimalFour,
            trigger: "blur"
          }, {
            validator: max100,
            trigger: "blur"
          }],
          mortgageInterestRate: [require('融资利率', {
            // trigger: "blur"
          }), {
            validator: decimalFour,
            trigger: "blur"
          }, {
            validator: max100,
            trigger: "blur"
          }],
          status: [require('认证信息', {
            trigger: "change",
            type: "number"
          })],
          remark: [require('认证备注', {
            trigger: "blur"
          })]
        },
        //七牛图片上传
        qiniuImage: {
          id: "qiniuImage", //图片预览的id   
          image_uri: [], //图片上传的列表  只含有url地址
        },

        qiniuImage1: {
          id: "qiniuImage1",
          image_uri: []
        }
      }
    },
    methods: {
      returnBack() {
        this.authDialogFormVisible.dialogFormVisible = false;
      },
      submitConfirmForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const params = {
              "businessSysUsersId": this.dialogForm.businessSysUsersId, //业务员
              "category": this.dialogForm.category, //经销商类别
              "id": this.dialogForm.id,
              "interestRate": this.dialogForm.interestRate, //垫资利率 ,
              "mortgageInterestRate": this.dialogForm.mortgageInterestRate, // 融资利率
              "pushSysUsersId": this.dialogForm.pushSysUsersId, // 地推人员
              "remark": this.dialogForm.remark, //实名认证备注 ,
              "resourceSysUsersId": this.dialogForm.resourceSysUsersId, //资源人员
              "status": this.dialogForm.status //认证状态
            }

            agentHttp.putJson('adminApi/admin/dealer_ordinary/senior_authentication', params).then((data) => {
              this.authDialogFormVisible.dialogFormVisible = false;
              this.$message.success(data.data || "修改成功");
              this.$emit('Refresh', null);
            })

          } else {

          }
        });
      },
      selectData() {
        agentHttp.get('adminApi/admin/dealer_ordinary/select_dealer/' + this.authDialogFormVisible.id).then(
          (data) => {
            if (data.success) {
              this.dialogForm = data.data.dealer;
              this.type = data.data.type;
              this.ditui = data.data.ditui;
              this.ziyuan = data.data.ziyuan;
              this.yewuyuan = data.data.yewuyuan;
              this.dialogForm.status == 1 ? this.dialogForm.status = this.dialogForm.status : this.dialogForm.status =
                2;
              this.dialogForm.idCardPics = {
                id: Math.ceil(Math.random() * 100000),
                image_uri: this.dialogForm.idCardPic ? this.dialogForm.idCardPic.split(',').notempty() : [] //身份证图片
              }
              this.dialogForm.legalPersonPics = {
                id: Math.ceil(Math.random() * 100000),
                image_uri: this.dialogForm.legalPersonPic ? this.dialogForm.legalPersonPic.split(',').notempty() : [] //法人身份证图片
              }
              this.dialogForm.businessLicenses = {
                id: Math.ceil(Math.random() * 100000),
                image_uri: this.dialogForm.businessLicense ? this.dialogForm.businessLicense.split(',').notempty() :
                  [] //营业执照图片
              }



            }
          })
      },
      FormatInterestRate(val) {
        this.dialogForm[val] = ((this.dialogForm[val] || "") - 0).toFixed(4);
      },
      getDate(time) {
        return timestampToTime(time);
      }
    }
  };
</script>
